package com.sims.daoImp;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sims.bean.ElectricalFile;
import com.sims.dao.IElectricalFileDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * ElectricalFile entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.sims.bean.ElectricalFile
 * @author MyEclipse Persistence Tools
 */

public class ElectricalFileDAO extends HibernateDaoSupport implements IElectricalFileDAO {
	private static final Logger log = LoggerFactory
			.getLogger(ElectricalFileDAO.class);
	// property constants
	public static final String IDEOLOGY = "ideology";
	public static final String EVALUATION = "evaluation";
	public static final String PHYSICAL = "physical";
	public static final String FAITH_RECORD = "faithRecord";

	@Override
	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#save(com.sims.bean.ElectricalFile)
	 */
	@Override
	public void save(ElectricalFile transientInstance) {
		log.debug("saving ElectricalFile instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#delete(com.sims.bean.ElectricalFile)
	 */
	@Override
	public void delete(ElectricalFile persistentInstance) {
		log.debug("deleting ElectricalFile instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findById(java.lang.Integer)
	 */
	@Override
	public ElectricalFile findById(java.lang.Integer id) {
		log.debug("getting ElectricalFile instance with id: " + id);
		try {
			ElectricalFile instance = (ElectricalFile) getHibernateTemplate()
					.get("com.sims.bean.ElectricalFile", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findByExample(com.sims.bean.ElectricalFile)
	 */
	@Override
	public List findByExample(ElectricalFile instance) {
		log.debug("finding ElectricalFile instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ElectricalFile instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ElectricalFile as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findByIdeology(java.lang.Object)
	 */
	@Override
	public List findByIdeology(Object ideology) {
		return findByProperty(IDEOLOGY, ideology);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findByEvaluation(java.lang.Object)
	 */
	@Override
	public List findByEvaluation(Object evaluation) {
		return findByProperty(EVALUATION, evaluation);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findByPhysical(java.lang.Object)
	 */
	@Override
	public List findByPhysical(Object physical) {
		return findByProperty(PHYSICAL, physical);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findByFaithRecord(java.lang.Object)
	 */
	@Override
	public List findByFaithRecord(Object faithRecord) {
		return findByProperty(FAITH_RECORD, faithRecord);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#findAll()
	 */
	@Override
	public List findAll() {
		log.debug("finding all ElectricalFile instances");
		try {
			String queryString = "from ElectricalFile";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#merge(com.sims.bean.ElectricalFile)
	 */
	@Override
	public ElectricalFile merge(ElectricalFile detachedInstance) {
		log.debug("merging ElectricalFile instance");
		try {
			ElectricalFile result = getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#attachDirty(com.sims.bean.ElectricalFile)
	 */
	@Override
	public void attachDirty(ElectricalFile instance) {
		log.debug("attaching dirty ElectricalFile instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IElectricalFileDAO#attachClean(com.sims.bean.ElectricalFile)
	 */
	@Override
	public void attachClean(ElectricalFile instance) {
		log.debug("attaching clean ElectricalFile instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IElectricalFileDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IElectricalFileDAO) ctx.getBean("ElectricalFileDAO");
	}
}